﻿using IdentityServer4.Models;
using IdentityServer4.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WYFast.IdentityServer
{
    public class ProfileService : IProfileService
    {

        /*
          
            IdentityServer提供了接口访问用户信息，但是默认返回的数据只有sub，
            就是上面设置的subject: context.UserName，
        
            要返回更多的信息，需要实现IProfileService接口：
        
             
             */
        public Task GetProfileDataAsync(ProfileDataRequestContext context)
        {
            try
            {
                //depending on the scope accessing the user data.
                var claims = context.Subject.Claims.ToList();

                //set issued claims to return
                context.IssuedClaims = claims.ToList();
                return Task.CompletedTask;
            }
            catch (Exception ex)
            {
                //log your error
                return Task.FromException(ex);
            }

        }

        public Task IsActiveAsync(IsActiveContext context)
        {
            context.IsActive = true;
            return Task.CompletedTask;
        }
    }
}
